package com.bzm.common.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.bzm.config.BzmGlobalConfig;


/**
 * @Description:发布订阅模式
 * @author hemiao
 * @time:2022年10月6日 下午1:53:14
 */
@Configuration
public class FanoutExchangeConfig {
	
	
	/**
	 * im mq 广播交换机
	 */
	public static String im_chat_fanout_exchange_mq = "im.chat.fanout.exchange";
	
	/**
	 * @Description:队列
	 * @return
	 * Queue
	 * @exception:
	 * @author: hemiao
	 * @time:2022年10月6日 下午1:59:52
	 */
	@Bean(name = "imMsgFanoutQueue")
	public Queue imMsgFanoutQueue() {
		return new Queue(BzmGlobalConfig.im_msg_fanout_queue_mq);
	}
	
	/**
	 * @Description:配置广播路由器
	 * @return
	 * DirectExchange
	 * @exception:
	 * @author: hemiao
	 * @time:2022年10月6日 下午1:59:38
	 */
	@Bean("imChatFanoutExchange")
	public FanoutExchange imChatFanoutExchange() {
		return new FanoutExchange(im_chat_fanout_exchange_mq);
	}
	
	/**
	 * @Description:绑定交换机 和 队列
	 * @param queue	交换机
	 * @param imChatFanoutExchange	广播路由器
	 * @return
	 * Binding
	 * @exception:
	 * @author: hemiao
	 * @time:2022年10月6日 下午2:00:03
	 */
	@Bean("imChatFanoutExchangeBind")
	public Binding imChatFanoutExchangeBind(@Qualifier("imMsgFanoutQueue") Queue queue,
			@Qualifier("imChatFanoutExchange")FanoutExchange fanoutExchange) {
		return BindingBuilder.bind(queue).to(fanoutExchange);
	}
	
}
